public class Draw {
    private int height;

    public Draw(int h) {
        if (h < 3) {
            System.out.println("高度设置不合理，至少需要超过3行。");
            height = 3;
        } else {
            height = h;
        }
    }

    public void drawSanjiaoxing() {
        for (int i = 1; i <= height; i++) {
            for (int j = 0; j < height - i; j++) {
                System.out.print(" ");
            }
            for (int k = 0; k < 2 * i - 1; k++) {
                System.out.print("*");
            }
            System.out.println();
        }
    }

    public void drawJvxing() {
        for (int i = 0; i < height; i++) {
            for (int j = 0; j < height; j++) {
                System.out.print("*");
            }
            System.out.println();
        }
    }

    public void drawSquare() {
        drawJvxing();
    }

    public void drawParallelogram() {
        for (int i = 0; i < height; i++) {
            for (int j = 0; j < i; j++) {
                System.out.print(" ");
            }
            for (int k = 0; k < height; k++) {
                System.out.print("*");
            }
            System.out.println();
        }
    }

    public static void main(String[] args) {
        Draw drawObj = new Draw(5);

        System.out.println("绘制三角形：");
        drawObj.drawSanjiaoxing();
        System.out.println();

        System.out.println("绘制矩形：");
        drawObj.drawJvxing();
        System.out.println();

        System.out.println("绘制正方形：");
        drawObj.drawSquare();
        System.out.println();

        System.out.println("绘制平行四边形：");
        drawObj.drawParallelogram();
    }
}
